<template>
	<div >
	  <div >
		<header v-if="type===1">
		  <div class="sn-flex sn-row-center hidden-sm-and-down">
			<el-input v-model="searchValue" placeholder="输入员工名称进行筛选" style="width: 200px" clearable
			  @keyup.enter.native="currentChange(1)" />
			<el-button class="sn-btn" style="margin-left: 10px" type="primary" icon="el-icon-search"
			  @click="currentChange(1)">
			  搜索
			</el-button>
		  </div>
		  <div class="hidden-sm-and-up">
			<el-input v-model="searchValue" placeholder="输入员工名称进行筛选" style="width: 200px" clearable
			  @keyup.enter.native="currentChange(1)" />
			<el-button style="margin-left: 4px" type="primary" class="sn-btn" icon="el-icon-search"
			  @click="currentChange(1)">
			  搜索
			</el-button>
		  </div>
		</header>
		<section>
		  <global-table style="margin-top: 20px;" :showNumber="false" :pageIndex="currentPage" :pageSize="pageSize" :headerData="initData"
			:data="tabelData" :isFullScreen="false" :operateW="80">
			<template #nickname="scope">
				<span >{{scope.row.nickname||''}}{{ scope.row.realname?'('+scope.row.realname+')':''}}</span>
			</template>
			<template #operate="scope">
				<el-button type="primary" v-if="choosePersonId!==scope.row.userId"  size="mini" @click="chooseStaffFn(scope.row)">选择</el-button>
			  		<span class="el-icon-check" v-else></span>
			</template>
		  </global-table>
		</section>
		<footer>
		  <el-pagination @current-change="currentChange" :current-page.sync="currentPage" :page-size="pageSize"
			layout="prev, pager, next, jumper" :pager-count="7" class="sn-pagination" hide-on-single-page
			style="text-align: center;" :total="totalNum" background>
			>
		  </el-pagination>
		</footer>
	  </div>
	</div>
  </template>
  
  <script>
  import GlobalTable from '@/components/GlobalTable';
  import {GetEmployeePage } from '@/api/accessmanage';
  import {GetEnterpriseBartenders} from '@/api/enterprise'
  import { guid } from '@/utils'
  export default {
	components: { GlobalTable },
	data() {
	  return {
		tabelData: [],
		initData: [
		  
		],
		currentPage: 1,
		pageSize: 10,
		totalNum: 0,
		searchValue: '',
		choosePersonId:'',
	  }
	},
	props:{
		personId:{
			default:'',
			type:String
		},
		enterpriseId:{
			default:'',
			type:String
		},
		type:{
			default:1,
			type:Number
		}
	},
	created() {
		this.choosePersonId = this.personId;
		if(this.type === 1){
			this.initData = [{
				label: '员工名称',
				value: 'employeeName',
				id: guid(),
				width:220
			}]
		}
		if(this.type === 2){
			this.initData = [{
				label: '调酒师名称',
				value: 'nickname',
				id: guid(),
				isCustom: true,
				width:220
			}]
		}
	  this.getDataListFn();
	},
	methods: {
	  currentChange(val) {
		this.currentPage = val;
		this.getDataListFn();
	  },
	  chooseStaffFn(data){
		this.choosePersonId = data.userId;
		this.$emit('choosePerson',data.userId);
	  },
	  async getDataListFn() {
		let params = {
		  pageIndex: this.currentPage,
		  pageSize: this.pageSize,
		}
		let res;
		if(this.type===1){
			params.EmployeeName = this.searchValue;
			res = await GetEmployeePage(params);
			if (res.code === 200) {
				this.tabelData = res.data.list;
				this.totalNum = res.data.totalCount;
			} else {
				this.tabelData = [];
				this.$message.error('获取员工列表失败，错误信息：' + res.erroMessage);
			}
		}
		if(this.type===2){
			params.id = this.enterpriseId;
			res = await GetEnterpriseBartenders(params);
			if (res.code === 200) {
				this.tabelData = res.data;
				this.totalNum = 0;
			} else {
				this.tabelData = [];
				this.$message.error('获取企业的调酒师列表失败，错误信息：' + res.erroMessage);
			}
		}
	
	  },
	}
  };
  </script>
  
  <style lang="scss" scoped>

  </style>